import { isObject, useDateFormat } from '@vueuse/core'

export const noSideSpace = value => !value.startsWith(' ') && !value.endsWith(' ')

export const timeFormat = time => {
  return useDateFormat(+new Date(time), 'YYYY-MM-DD HH:mm:ss').value
}

export const copyText = value => {
  navigator.clipboard.writeText(value).then(() => {
    $message.success('已成功复制到剪切板。')
  }).catch(() => {
    $message.success('复制失败，请重试或手动复制！')
  })
}

export const sleep = ms => {
  return new Promise(resolve => setTimeout(resolve, ms))
}

export const deepMerge = (src, target) => {
  let key
  for (key in target) {
    src[key] = isObject(src[key])
      ? deepMerge(src[key], target[key])
      : (src[key] = target[key])
  }
  return src
}